﻿using System.Collections.Generic;
using System.Data.Entity;
using System.Linq;

namespace WindMill.Services
{
    public class OracleConnectionPool
    {
        private static OracleConnectionPool _instance = null;
        private List<DbContext> _dbContexts;

        public List<DbContext>  DbContexts
        {
            get { return _dbContexts; }
            set { _dbContexts = value; }
        }

        protected OracleConnectionPool()
        {
            DbContexts = new List<DbContext>();
        }

        public static OracleConnectionPool GetPool()
        {
            return _instance ?? (_instance = new OracleConnectionPool());
        }

        public DbContext GetDbContext<T>() where T : DbContext, new()
        {
            if (!DbContexts.Any(c => c is T))
                DbContexts.Add(new T());

            return DbContexts.First(c => c is T);
        }
    }
}